<?php
require_once('keys.php');
require_once('epiOAuth/EpiCurl.php');
require_once('epiOAuth/EpiOAuth.php');
require_once('epiOAuth/EpiTwitter.php');
require_once('epiOAuth/SimpleTwitter.php');
require_once("login/class.session.php");

//define("FULL_PATH", "/demo/");
define("SELECT_COLUMNS", "username, isadmin, displayname, email, city, country, state, members, genre, bio, influences, website, recordlabel, soundslike");




// Checks if an entry is null
function is_not_null($value) {
  if (isset($value) && trim($value) != "") {
    return true;
  }
  
  return false;
}

// Check if a user has already added the network
function is_integrated_with($network, $userid) {
	$query = "SELECT * FROM {$network} WHERE user_id = '{$userid}'";
	  
	$networkExists = query_select($query);
	
    if(!empty($networkExists)) {
		return $networkExists[0];
    }
  
  return false;
}

// Adds the user's OAuth token and username for a social network to the database
function update_network_token($network, $userid, $token=null, $secret=null, $username=null) {
	$vals = array("user_id" => $userid, 
	"username" => $username, 
	"usertoken" => $token, 
	"usersecret" => $secret);
	
	$where = array("user_id" => $userid);
	
	if(!is_integrated_with($network, $userid)) {
		query_insert($network,  $vals);
		return true;
	}
	else {
		query_update($network, $vals, $where);
		return true;
	}
	return false;
}



function state_selection($current) {
    echo '<select name="state">';
    echo '<option value = ""'; 
    if ($current == "") {
      echo ' selected="selected"';
    }
    echo '>-----------</option>';
    $states = array(
        'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
    );
    foreach ($states as $state_name) {
        
        echo '<option value="' . $state_name . '"';
        if ($current == $state_name) {
          echo ' selected="selected"';
        }
        echo '>' . $state_name . '</option>';
    }
    echo '</select>';
}


function read_from_file($file, $delimiter="\n") {
    // an array of the lines from the file
    $lines = array();
    // open the file for reading
    $fp = fopen( $file, 'r' );

    // loop over the file pointer
    while ( !feof ( $fp) )
    {
        //read the line into a buffer
        $buffer = stream_get_line( $fp, 1024, $delimiter );       
        $lines[] = $buffer;         
        $buffer = '';
    }
    print_r($lines);
    return $lines;
}

function country_selection($current) {
    echo '<select name="country">';
    echo '<option value = ""'; 
    if ($current == "") {
      echo ' selected="selected"';
    }
    echo '>-----------</option>';    
    $countries = read_from_file("countries.txt");      
    foreach ($countries as $country_name) {      
      echo '<option value="' . $country_name . '"';
        if ($current == $country_name) {
          echo ' selected="selected"';
        }
      echo '>' . $country_name . '</option>';
    }
    echo '</select>';
}



?>
